//
//  DataViewModel.m
//  DebugDemo
//
//  Created by XFB on 2019/1/7.
//  Copyright © 2019年 ZhouCheng. All rights reserved.
//

#import "DataViewModel.h"

@implementation DataViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    self.successObject = [RACSubject subject];
    self.failureObject = [RACSubject subject];
    self.dataModel = [DataModel new];
}

- (void)exchangeData
{
    @weakify(self);
 
    [self.dataModel getDataSuccess:^(NSDictionary * _Nonnull dict) {
        
        @strongify(self);
        NSArray *resultArray = [dict objectForKey:@"data"];
        [self.successObject sendNext:resultArray];
        
    } failure:^(NSDictionary * _Nonnull dict) {
        
        @strongify(self);
        NSString *string = [dict objectForKey:@"error"];
        
        if (string.length > 0 || ![string isEqualToString:@""]) {
            [self.failureObject sendNext:string];
        }
    }];
    
}

@end
